using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.AcmsControls
{
    [ToolboxData("<{0}:FlashContentControlDisplay runat=server></{0}:FlashContentControlDisplay>")]
    public class FlashContentControlDisplay : BaseContentControlDisplay
    {
        private FlashContentControlProperties properties;
        public FlashContentControlProperties Properties
        {
            get 
            {
                if (properties == null)
                    properties = new FlashContentControlProperties();
                return properties; 
            }
        }


        protected override BaseContentControlProperties GetProperties()
        {
            return Properties;
        }

        protected override void SetProperties(BaseContentControlProperties properties)
        {
            this.properties = properties as FlashContentControlProperties;
        }

        Acms.WebControls.FlashControl ctrl;

        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            ctrl = new Acms.WebControls.FlashControl();
            this.Controls.Add(ctrl);
            base.CreateChildControls();
        }

        protected override void DataBindChildren()
        {
            if (Properties.HasResource())
            {
                ctrl.FlashFileUrl = string.Format("~/File.aspx?id={0}", Properties.ResourceId);
                if (Properties.Width == 0 || (MaxWidth > 0 && Properties.Width > MaxWidth))
                {
                    ctrl.Width = MaxWidth;
                }
                else
                {
                    ctrl.Width = Properties.Width;
                }
                if (Properties.Height == 0 || (MaxHeight > 0 && Properties.Height > MaxHeight))
                {
                    ctrl.Height = MaxHeight;
                }
                else
                {
                    ctrl.Height = Properties.Height;
                }
                ctrl.MinVersion = Properties.MinVersion;
                ctrl.WMode = this.WMode;
            }
        }
        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            
        }

        public override void RenderEndTag(HtmlTextWriter writer)
        {
        }

        private int maxWidth;
        public int MaxWidth
        {
            get { return maxWidth; }
            set { maxWidth = value; }
        }

        private int maxHeight;
        public int MaxHeight
        {
            get { return maxHeight; }
            set { maxHeight = value; }
        }

        private Acms.WebControls.FlashControl.WModes wMode;
        public Acms.WebControls.FlashControl.WModes WMode
        {
            get { return wMode; }
            set { wMode = value; }
        }
	
        public Dictionary<string, string> Variables
        {
            get{EnsureChildControls();return ctrl.Variables;}
        }
	

    }
}
